package com.bysc.commentservice.api;


import com.bysc.baseservice.handler.BaiYunException;
import com.bysc.commentservice.entity.CommentParent;
import com.bysc.commentservice.service.GetParentCommentService;
import com.bysc.commonutils.Results;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class getParentComment {

    @Autowired
    private GetParentCommentService getParentService;

    @ApiOperation(value = "分页查询最热(点赞最多)父评论")
    @PostMapping("getCommentListByPostIdOrderBycreatTime/{page}/{limit}")
    public Results getCommentListByPostIdOrderByLike(@ApiParam(name = "id", value = "评论id", required = true)String id,@ApiParam(name = "page", value = "查询页数", required = true)
                                                 @PathVariable Integer page, @ApiParam(name = "limit", value = "查询数量", required = true)
                                                 @PathVariable Integer limit) {
        try {
            List<CommentParent> list = getParentService.getCommentListByPostIdOrderByLike(id,page, limit);
            return Results.ok().data("commentList", list);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BaiYunException(20001, "error");
        }
    }
}
